﻿using ERP.ERPSystem.ProductionSystem;
using ERP.ERPSystem.ProductionSystem.Dto;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace ERP.Web.Controllers.ProductionSystem
{
    /// <summary>
    /// 工艺路线控制器，负责处理来自前端页面的HTTP请求。
    /// </summary>
    [Route("[controller]")] // 定义该控制器下所有Action的基础路由为 "/Workmanship"
    public class WorkmanshipController : Controller
    {
        /// <summary>
        /// 工艺路线服务接口的私有只读实例
        /// </summary>
        private readonly IWorkmanshipService _workmanshipService;
        /// <summary>
        /// 构造函数，通过依赖注入方式获取工艺路线服务的实例。
        /// </summary>
        /// <param name="workmanshipService">工艺路线服务</param>
        public WorkmanshipController(IWorkmanshipService workmanshipService)
        {
            _workmanshipService = workmanshipService;
        }

        /// <summary>
        /// 返回工艺路线管理的首页视图。
        /// </summary>
        /// <returns>WorkmanshipIndex.cshtml 视图</returns>
        [HttpGet]
        [Route("WorkmanshipIndex")] // 路由: GET /Workmanship/WorkmanshipIndex
        public IActionResult WorkmanshipIndex()
        {
            return View();
        }

        /// <summary>
        /// (API) 获取分页的工艺流程列表。
        /// </summary>
        /// <param name="input">包含筛选、排序和分页信息的查询条件DTO。</param>
        /// <returns>一个包含工艺流程列表和总数的分页结果对象。</returns>
        [HttpGet]
        [Route("api/list")] // 路由: GET /Workmanship/api/list
        public Task<PagedResultDto<WorkmanshipDTO>> GetListAsync(GetWorkmanshipInputDto input)
        {
            return _workmanshipService.GetListAsync(input);
        }

        /// <summary>
        /// (API) 创建一个新的工艺流程。
        /// </summary>
        /// <param name="input">从请求体(Body)中获取的创建所需的数据。</param>
        /// <returns>创建成功后的工艺流程DTO。</returns>
        [HttpPost]
        [Route("api/create")] // 路由: POST /Workmanship/api/create
        public Task<WorkmanshipDTO> CreateAsync([FromBody] CreateUpdateWorkmanshipDto input)
        {
            return _workmanshipService.CreateAsync(input);
        }

        /// <summary>
        /// (API) 更新一个已存在的工艺流程。
        /// </summary>
        /// <param name="id">从URL中获取的要更新的工艺流程ID。</param>
        /// <param name="input">从请求体(Body)中获取的更新所需的数据。</param>
        /// <returns>更新成功后的工艺流程DTO。</returns>
        [HttpPut]
        [Route("api/update/{id}")] // 路由: PUT /Workmanship/api/update/5
        public Task<WorkmanshipDTO> UpdateAsync(int id, [FromBody] CreateUpdateWorkmanshipDto input)
        {
            return _workmanshipService.UpdateAsync(id, input);
        }

        /// <summary>
        /// (API) 删除一个工艺流程。
        /// </summary>
        /// <param name="id">从URL中获取的要删除的工艺流程ID。</param>
        /// <returns>一个表示操作完成的Task。</returns>
        [HttpDelete]
        [Route("api/delete/{id}")] // 路由: DELETE /Workmanship/api/delete/5
        public Task DeleteAsync(int id)
        {
            return _workmanshipService.DeleteAsync(id);
        }

        /// <summary>
        /// (API) 批量删除工艺流程。
        /// </summary>
        /// <param name="ids">从请求体(Body)中获取的要删除的ID集合。</param>
        /// <returns>一个表示操作完成的Task。</returns>
        [HttpPost]
        [Route("api/batch-delete")] // 路由: POST /Workmanship/api/batch-delete
        public Task DeleteManyAsync([FromBody] IEnumerable<int> ids)
        {
            return _workmanshipService.DeleteManyAsync(ids);
        }
    }
}
